package com.younio.local.config;

import com.alibaba.fastjson.parser.ParserConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @desc:
 * @author: lan     [1728209643@qq.com]
 * @date: 2018-09-11 15:45
 */
@Configuration
public class RedisConfig {


    @Bean
    public RedisTemplate<?, ?> jsonRedisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<?, ?> redisTemplate = new RedisTemplate<>();

        ParserConfig.getGlobalInstance().setAutoTypeSupport(Boolean.TRUE);
        redisTemplate.setKeySerializer(new JsonRedisSerializer<>(String.class));
        redisTemplate.setHashKeySerializer(new JsonRedisSerializer<>(Object.class));
        redisTemplate.setValueSerializer(new JsonRedisSerializer<>(Object.class));
        redisTemplate.setHashValueSerializer(new JsonRedisSerializer<>(Object.class));

        redisTemplate.setConnectionFactory(factory);

        return redisTemplate;
    }

}





























































































































